<?php
/**
 * Created by PhpStorm.
 * User: Admin
 * Date: 2018/7/23
 * Time: 22:05
 */
namespace app\common\model;

use fast\BaiduNlp;
use think\Model;

class WorkTopic extends Model
{
    protected $name='work_cate';

    protected $autoWriteTimestamp=false;

    public static function auto_cate($title,$content)
    {
        $nlp=new BaiduNlp();
        $res=$nlp->auto_cate($title,$content);
        $res=$res['item'];
        if (!empty($res['lv1_tag_list'])){
            foreach ($res['lv1_tag_list'] as $n){
                db('work_cate')->insertGetId([
                    'pid'=>$v['id'],
                    'level'=>1,
                    'tag'=>$n['tag'],
                    'score'=>$n['score']
                ]);
            }
        }
        if (!empty($res['lv2_tag_list'])){
            foreach ($res['lv2_tag_list'] as $n){
                db('work_cate')->insertGetId([
                    'pid'=>$v['id'],
                    'level'=>2,
                    'tag'=>$n['tag'],
                    'score'=>$n['score']
                ]);
            }
        }
        return true;
    }
}